<!DOCTYPE html>
<html lang="en">
<head>
    <meta charset="UTF-8">
    <title>BIND</title>
</head>
<body>
<script>
    function ShowRandom() {
        this.number=-1;
    }
    ShowRandom.prototype.createRandom = function () {
        this.number = parseInt(Math.random()*10+1);
    };
    ShowRandom.prototype.showRandom = function () {
        console.log(this.number)
    };
    //bind改变this指向，setInterval中原本this表示window，使用bind之后将指向ShowWindow构造函数
    ShowRandom.prototype.circle = function () {
        setInterval(function () {
            this.showRandom();
            this.createRandom();
        }.bind(this),2000);

    };
    var sr = new ShowRandom();
    sr.circle();
</script>
</body>
</html>